home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlib43 / mntlib / purec / vfork.s < prev    next >
Text File  |  1992-06-26  |  2KB  |  52 lines

  1. ; From the mintlib.
  2. ; Pure C version 21-6-92 bm
  3. ;
  4. ; vfork for MiNT. Note that the return address must be popped off the stack,
  5. ; or else it could be clobbered by the child and the parent would be left
  6. ; returning to la-la land. Also note that MiNT guarantees that register a1
  7. ; will be preserved across a vfork() system call.
  8. ;
  9.     .globl    vfork
  10.     .globl    __mint        ; MiNT version kept here
  11.     .comm    L_vfsav,128
  12.     .globl errno
  13.     .globl tfork        ; thread.c
  14.     .text
  15.     .even
  16. vfork:
  17.     move.l    (sp)+,a1    ; save return address; this is important!
  18.     tst.w    __mint
  19.     beq    L_TOS            ; go do the TOS thing
  20.     move.w    #$113,-(sp)    ; push MiNT Pvfork() parameter
  21.     trap    #1            ; Vfork
  22.     addq.l    #2,sp
  23.     tst.l    d0            ; error??
  24.     bmi    L_err
  25.     jmp    (a1)            ; return
  26. L_TOS:
  27.     movem.l    d2-d7/a1-a6,L_vfsav    ; save registers
  28.     move.l #L_vfsav,d0    ; arguments are passed in a0 (func) and d0 (arg)
  29.     lea.l L_newprog,a0
  30.     jsr    tfork            ; tfork(L_newprog, L_vfsav)
  31.     movem.l    L_vfsav,d2-d7/a1-a6    ; restore reggies
  32.     tst.l    d0            ; fork went OK??
  33.     bmi    L_err            ; no -- error
  34.     jmp    (a1)            ; return to caller
  35. L_err:
  36.     neg.l    d0
  37.     move.w    d0,errno    ; save error code in errno
  38.     moveq.l    #-1,d0        ; return -1
  39.     jmp    (a1)            ; return
  40.  
  41. ;
  42. ; L_newprog: here is where the child starts executing, with argument
  43. ; L_vfsav. We restore registers, zero d0, and jump back to parent
  44. ;
  45.  
  46. L_newprog:
  47.     addq.l    #4,sp        ; pop useless return address
  48.     move.l    d0,a0        ; get address of save area
  49.     movem.l    (a0),d2-d7/a1-a6    ; restore reggies
  50.     clr.l    d0            ; child always returns 0 from vfork
  51.     jmp    (a1)            ; back to caller, as child process
  52.